import { createCrudApi } from '@/utils/apiFactory';
import request from '@/utils/unirequest';
import type { IResult } from '@/type/common';
import type {
  ISysHrTransferRequestBill,
  ISysHrTransferRequestBillView,
  ISysHrTransferRequestBillVm,
  ISysPersonSearchQuery,
  ISysPersonSearchResponse
} from './interface';

// 岗位信息接口
interface ISysJobPosition {
  Value: string;
  Text: string;
  Id?: string;
  Name?: string;
  Salary?: number; // 岗位薪资
}

export default function SysHrTransferRequestBillApi() {
  // 基础CRUD用工厂生成
  const baseCrud = createCrudApi<
    ISysHrTransferRequestBillView,
    ISysHrTransferRequestBillVm,
    ISysHrTransferRequestBill
  >('/api/SysHrTransferRequestBill');

  return {
    ...baseCrud,
    // 额外的特殊接口
    // 获取单据编号接口
    async getBillCode(): Promise<IResult<string>> {
      return await request.get('/api/SysHrTransferRequestBill/PredictCode');
    },
    // 审核接口
    async approve(data: ISysHrTransferRequestBillVm): Promise<ISysHrTransferRequestBill> {
      return await request.post('/api/SysHrTransferRequestBill/approve?tag=', data);
    },
    // 员工搜索接口
    async searchPersons(query: ISysPersonSearchQuery): Promise<ISysPersonSearchResponse> {
      return await request.post('/api/SysPerson/Search', query);
    },
    // 根据部门ID获取岗位列表
    async getSysJobPositions(groupId: string): Promise<ISysJobPosition[]> {
      return await request.get(`/api/common/getjobpositions?groupId=${groupId}`);
    },
  };
}